# Maintainer: Carter Li <zhangsongcui@live.cn>

_realname=fastfetch
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.5
pkgrel=1
pkgdesc="A neofetch-like tool for fetching system information and displaying them in a pretty way (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/fastfetch-cli/fastfetch"
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-vulkan-loader"
             "${MINGW_PACKAGE_PREFIX}-opencl-icd")
optdepends=("${MINGW_PACKAGE_PREFIX}-vulkan-loader: For Vulkan support detection"
            "${MINGW_PACKAGE_PREFIX}-opencl-icd: For OpenCL support detection")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/fastfetch-cli/fastfetch/archive/refs/tags/${pkgver}.tar.gz")
sha256sums=('8046eb856fd95d9896220238c966125fb05e451e65d8cfc7eb25483767612235')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
}

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=;-DCMAKE_INSTALL_SYSCONFDIR=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    "${extra_config[@]}" \
    -DCMAKE_INSTALL_SYSCONFDIR=${MINGW_PREFIX}/etc \
    ../${_realname}-${pkgver}
  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
